#include "reg52.h"
#include "Delay.h"
#define KeyPort P3

unsigned char KeyScan(void)
{
	unsigned char H,L;
	KeyPort=0x0f;
	H=KeyPort&0x0f;
	if(H!=0x0f)
	{
		DelayMs(10);
		if((KeyPort&0x0f)!=0x0f)
		{
			H=KeyPort&0x0f;
			KeyPort=H|0xf0;
			L=KeyPort&0xf0;    
			
			while((KeyPort&0xf0)!=0xf0);
			return (H+L);
		}
		
	}
	 return (0xff);
          
}	

unsigned char KeyPro()
{
	
	switch(KeyScan())
	{
		case 0x7e:return 1;break;
		case 0x7d:return 2;break;
		case 0x7b:return 3;break;
		case 0x77:return 4;break;
		case 0xbe:return 5;break;
		case 0xbd:return 6;break;
		case 0xbb:return 7;break;
		case 0xb7:return 8;break;
		case 0xde:return 9;break;
		case 0xdd:return 10;break;
		case 0xdb:return 11;break;
		case 0xd7:return 12;break;
		case 0xee:return 13;break;
		case 0xed:return 14;break;
		case 0xeb:return 15;break;
		case 0xe7:return 16;break;
		default:return 0xff;break;
		
	}

}
